home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / setbuf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  1.1 KB  |  55 lines

  1. /* was from Dale Schumacher's dLibs library */
  2.  
  3. #include <stdio.h>
  4. #include <assert.h>
  5. #include <memory.h>
  6.  
  7. void setbuf(fp, buf)
  8. register FILE *fp;
  9. char *buf;
  10. {
  11.     assert((fp != NULL));
  12.     
  13.     if(fp->_flag & _IOMYBUF)
  14.     free(fp->_base);
  15.     fp->_flag &= ~(_IOFBF | _IOLBF | _IONBF | _IOMYBUF);
  16.     fp->_cnt = 0;
  17.     if(fp->_base = (unsigned char *)buf)    /* assignment intentional */
  18.     {
  19.     fp->_flag |= _IOFBF;
  20.     /* this is intentionally not __DEFAULT_BUFSIZ__ ++jrb */
  21.     fp->_bsiz = BUFSIZ;
  22.     }
  23.     else
  24.     {
  25.     fp->_flag |= _IONBF;
  26.     fp->_base = &(fp->_ch);            /* use tiny buffer */
  27.     fp->_bsiz = 1;
  28.     }
  29.     fp->_ptr = fp->_base;
  30. }
  31.  
  32. /*
  33.  * bezerkly'ism
  34.  * change the buffering on stream from block/unbuffered to line buffered.
  35.  * should stream be flushed before change?? i think so.
  36.  *    ++jrb
  37.  */
  38. #define __SRC__
  39. #include <sys/types.h>
  40. #include <unistd.h>
  41.  
  42. void setlinebuf(fp)
  43. register FILE *fp;
  44. {
  45.     assert((fp != NULL));
  46.     
  47. #ifndef NDEBUG
  48.     assert((fflush(fp) != EOF));
  49. #else    
  50.     (void)fflush(fp);
  51. #endif
  52.     fp->_flag &= ~(_IOFBF | _IONBF);
  53.     fp->_flag |=  _IOLBF;
  54. }
  55.